package cn.elwy.rcp.ui.widget;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;

import cn.elwy.rcp.ui.util.ColorUtil;

/**
 * 自定义Tab按钮类
 * 
 * @author huangsq
 * @version 1.0, 2013-11-20
 * @since 1.0, 2013-11-20
 */

public class CTabButton extends CButton {
  CTabComposite parent;
  CButton cButton;
  int x, y, width, height = 0;
  Control control; // the tab page

  public Control getControl() {
    return control;
  }

  public CTabButton(CTabComposite parent) {
    this(parent, SWT.RADIO, parent.getItemCount());
  }

  public CTabButton(CTabComposite parent, int style) {
    this(parent, style, parent.getItemCount());
  }

  public CTabButton(CTabComposite parent, int style, int index) {
    super(parent, style);
    parent.createItem(this, index);
  }

  /**
   * 设置默认颜色
   */
  @Override
  protected void setDefaultColors() {
    fontColor = ColorUtil.getColor(0, 0, 0);
    hoverFontColor = ColorUtil.getColor(0, 0, 0);
    pressedFontColor = ColorUtil.getColor(255, 255, 255);
    inactiveFontColor = ColorUtil.getColor(187, 187, 187);
    selectedFontColor = ColorUtil.getColor(160, 107, 38);
    borderColor = ColorUtil.getColor(187, 187, 187);
    hoverBorderColor = ColorUtil.getColor(147, 147, 147);
    pressedBorderColor = ColorUtil.getColor(147, 147, 147);
    inactiveBorderColor = ColorUtil.getColor(200, 200, 200);
    selectedBorderColor = ColorUtil.getColor(160, 107, 38);
    foregroundColor = ColorUtil.getColor(248, 248, 248);
    backgroundColor = ColorUtil.getColor(228, 228, 228);
    pressedFgColor = ColorUtil.getColor(120, 120, 120);
    pressedBgColor = ColorUtil.getColor(150, 150, 150);
    hoverFgColor = ColorUtil.getColor(248, 248, 248);
    hoverBgColor = ColorUtil.getColor(228, 228, 228);
    inactiveFgColor = ColorUtil.getColor(248, 248, 248);
    inactiveBgColor = ColorUtil.getColor(228, 228, 228);
    selectedFgColor = ColorUtil.getColor(238, 238, 238);
    selecteBgdColor = ColorUtil.getColor(218, 218, 218);
  }

  public void setControl(Control control) {
    this.control = control;
    parent.update(this);
  }

  @Override
  public void dispose() {
    if (isDisposed())
      return;
    super.dispose();
    parent = null;
    control = null;
  }

}
